<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>添加或编辑界面</title>
    <link rel="stylesheet" type="text/css" href="${s.base}/lib/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/css/base/index.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/css/base/theme/theme.css"/>
    <style>
        .w440{width: 440px !important;}
        .w490{width: 490px !important;}
        .input-prompt{/*position:absolute;right:-410px;*/font-size:12px;color:#999;width:400px;height:30px;line-height:30px;}
        .layui-input-inline{position:relative}
        .layui-textarea{border:1px solid #ddd; padding:5px 10px!important;}
    </style>
    <style>
        .w440 {
            width: 440px !important;
        }
    </style>
</head>
<body>
<div class="page-content-wrap clearfix">
    <form class="layui-form" id="tool">
        <div class="layui-tab">
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>社团名称：</label>
                        <div class="layui-input-inline w490">
                            <input type="text" name="title" lay-verify="required" value="${wxAssociation.title}"  placeholder="请输入社团名称" autocomplete="off" class="layui-input" maxlength="200">
                        </div>
                    </div>
                    <div class="layui-form-item" id="staff">
                        <label class="layui-form-label"><span class="red">*</span>教师姓名：</label>
                        <div class="layui-input-inline w490" style="position:relative; height: 100%;">
                            <div style="border:1px solid #ddd;padding-right:30px; min-height:28px;max-height: 100px; padding-left:7px; overflow-y: auto;">
                                <input type="hidden" class="cyt-table-input" id="userIds"  name="userIds" >
                                <input type="hidden" class="cyt-table-input" id="userNumber"  name="userNumber" value="${wxAssociation.userNumber}">
                                <span type="text" class="personlist"  id="userName" value="${wxAssociation.userName}"  autocomplete="off"><span style="color:#ccc!important;">请选择人员</span></span>
                            </div>
                            <div style="position:absolute;height:100%;line-height:30px;width:30px; display: table;right:0;top:calc(50% - 15px);" >
                                <div style="width: 100%; height: 100%; display: table-cell;vertical-align: middle"><i class="iconfont cy-a-blue FS20">&#xe6fb;</i></div>
                            </div>
                        </div>
                    </div>



                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;社团封面：</label>
                        <div class="layui-input-block cy-uploadpic-ctn" id="originalPath" style=" float:left;margin-left:0!important;position:relative;"></div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;社团简介：</label>
                        <div class="layui-input-inline w490">
                            <div class="layui-upload">
                                <textarea id="introduction" name="introduction" lay-verify="content" placeholder="请输入社团简介">${wxAssociation.introduction}</textarea>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block" style="margin-left: 0px !important;text-align: center">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="submitBtn">提交</button>
                <button type="button" id="cancel" class="layui-btn layui-btn-primary">取消</button>
                <button type="button" style="display: none;" id="save" class="layui-btn layui-btn-primary"></button>
            </div>
        </div>
    </form>
</div>
<script src="${s.base}/lib/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script src="${s.base}/mobile/js/common.js" type="text/javascript" charset="utf-8"></script>
<script src="${s.base}/js/common.js" type="text/javascript" charset="utf-8"></script>
<script src="${s.base}/lib/KnifeZ/ace/ace.js" type="text/javascript" charset="utf-8"></script>
<script>
    var applyId='${applyId}';
    var assid='${id}';
    layui.use(['jquery', 'form', 'page', 'layedit','dialog', 'fileUtil', 'baseutil'], function () {
        var $ = layui.jquery,
            form = layui.form,
            page = layui.page,
            layedit = layui.layedit,
            fileUtil = layui.fileUtil,
            dialog = layui.dialog;
        baseutil = layui.baseutil;
        //初始化富文本

        //初始化附件控件
        fileUtil.uploadImage('originalPath', "work/association/mult", '${wxAssociation.originalPath}');
        //这里怎么显示路径的情况分析  如何存取路径 而不是地址的情况
        //初始化富文本
        var index = baseutil.layeditKnifezBuild("introduction", 300);
        if(!isBlank(assid)){
            $("#userName").html("${wxAssociation.userName}");
            $("#userNumber").val("${wxAssociation.userNumber}");
//            $("#originalPath").val("${wxAssociation.originalPath                                                                      }");
            baseutil.post('/wx/wxeducationuser/getAllIdsByUserNumber', {"ids": "${wxAssociation.userNumber}"}, function (result) {
                if (0 == result.code) {
                    $("#userIds").val(result.data);
                }
            });
        }
        form.verify({
            content: function () {
                layedit.sync(index);

            }
        });

        debugger;
        //监听提交
        form.on('submit(submitBtn)', function (data) {

            data.field.id = '${wxAssociation.id}';
            data.field.applyId = applyId;
            data.field.userName = $("#userName").val();
            var stringIds =  $("#userIds").val();
            baseutil.post('/wx/wxeducationuser/NewgetAllIdsByUserNumber', {"ids":stringIds}, function (result) {
                if (0 == result.code) {
                    $("#userNumber").val(result.data);
                }
            });
            data.field.userNumber =  $("#userNumber").val();
            var nameStr= $("#userName").val();
            if(isBlank(assid)) {
                if (isBlank(nameStr)) {
                    dialog.msg("请选择教师");
                    return false;
                }
                var imageStr = $("#originalPath").val();
                if (isBlank(imageStr)) {
                    dialog.msg("请上传图片");
                    return false;
                }
            }
            var otherStr= $("#introduction").val();
            if(isBlank(otherStr)) {
                dialog.msg("请输入社团简介");
                return false;
            }


            baseutil.post("/work/association/wxassociation/addOrUpdate", data.field, function () {
                $("#save").click();
            });
            return false;
        });

        $("#staff").click(function () {
            var string = $("#userIds").val();
            dialog.popUpScTeacherApplyMultSelect("","userName",applyId,"教师选择","620px","560px",string,function (id,name) {
                $("#userIds").val(id);
                $("#userName").val(name);


            });
        });

    });
</script>
</body>
</html>